//
//  RootViewController.m
//  BlueTDevice
//
//  Created by MingmingSun on 16/8/20.
//  Copyright © 2016年 Sunmingming. All rights reserved.
//

#import "RootViewController.h"
#import "WubiLessonsViewController.h"
#import "WubiMainViewController.h"
#import "BigAboutUsViewController.h"
#import "BigDesktopViewController.h"

@interface RootViewController ()<UITabBarControllerDelegate>

@property(nonnull,strong) WubiLessonsViewController* c1;
@property(nonnull,strong) WubiMainViewController* c2;
@property(nonnull,strong) BigDesktopViewController* c3;
@property(nonnull,strong) UIViewController* c4;
@property(nonnull,strong) BigAboutUsViewController* c5;

@end

@implementation RootViewController

@synthesize c1,c2,c3,c4,c5;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
	self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
	if (self) {
		self.delegate = self;
		self.edgesForExtendedLayout = UIRectEdgeNone;
		
		self.c1= [WubiLessonsViewController new];
		c1.tabBarItem.title=@"课程";
		c1.tabBarItem.image=[UIImage imageNamed:@"book"];
		
		self.c2=[[WubiMainViewController alloc]init];
		c2.view.backgroundColor=[UIColor brownColor];
		c2.tabBarItem.title=@"练习";
		c2.tabBarItem.image=[UIImage imageNamed:@"pen_3"];
		
		self.c3=[[BigDesktopViewController alloc]init];
		c3.tabBarItem.title=@"动态";
		c3.tabBarItem.image=[UIImage imageNamed:@"book"];
		
		self.c4=[[UIViewController alloc]init];
		c4.tabBarItem.title=@"挑战";
		c4.tabBarItem.image=[UIImage imageNamed:@"pen_3"];
		
		self.c5=[BigAboutUsViewController new];
		c5.tabBarItem.title=@"我的";
		c5.tabBarItem.image=[UIImage imageNamed:@"documents"];
		
		self.viewControllers=@[c1,c2,c3,c5];
		self.selectedIndex = 0;
		self.title = [[[self.viewControllers objectAtIndex:self.selectedIndex] tabBarItem] title];
		self.tabBar.tintColor = [UIColor hollyGreenColor];
		self.tabBar.backgroundColor = [UIColor whiteColor];
	}
	return self;
}

-(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item{
	self.title = item.title;
}

- (void)viewDidLoad {
	[super viewDidLoad];
}

- (void)didReceiveMemoryWarning {
	[super didReceiveMemoryWarning];
	// Dispose of any resources that can be recreated.
}

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{
	self.navigationItem.leftBarButtonItem = nil;
	self.navigationItem.rightBarButtonItem = nil;
	if(viewController == self.c1){
		
	}else if(viewController == self.c2){
		if(![APPALL.mydefaults boolForKey:@"hasBoughtLevel"])
		{
			self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"开启练习" style:UIBarButtonItemStylePlain target:self.c2 action:@selector(rightPressed:)];
		}
	}else if(viewController == self.c3){
		
	}else if(viewController == self.c4){
		
	}else if(viewController == self.c5){
	}
	return true;
}

@end
